<template>
    <div>
        <el-dialog center class="global-dialog" v-model="dialogVisable" width="1000px" top="10vh" :show-close="false"
            :close-on-click-modal="false"  :before-close="close">
            <template #title>
                <div class="my-header" v-loading="detail_loading">
                    <el-tabs v-model="tabId" class="demo-tabs">
<!--                        <el-tab-pane label="流程图" name="12" v-if="flag == 3">-->
                        <el-tab-pane label="流程图" name="12" v-if="flag == 3">
                            <flowChart :processInstanceId="processInstanceId"></flowChart>
                        </el-tab-pane>

                        <el-tab-pane label="基本信息" name="1">
                            <el-divider content-position="left">
                                <span class="title-line">基本信息</span>
                            </el-divider>
                            <el-form :model="diaForm" ref="DiaForm" :rules="rules" label-width="110px" label-position="top"
                                status-icon>
                                <el-row :gutter="20">
                                    <el-col :span="6">
                                        <el-form-item label="人才类型" prop="expertType">
                                            <el-select v-model="diaForm.expertType" placeholder="请选择" style="width: 100%"
                                            @change="changeExpertType"  :disabled="flag == 3" clearable>
                                                <el-option :label="item.itemText" :value="item.itemValue"
                                                    :key="item.itemValue" v-for="item in expertTypeList" />
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="人才姓名" prop="expertName">
                                            <user-list-modal style="width: 100%" :disabled="flag == 3"
                                                v-if="diaForm.expertType == 1" v-model="diaForm.expertName"
                                                @update:modelValue="handleProjectLeader" :default-users="[]"
                                                :multiple="false" :devType="'platform'" />
                                            <el-input v-else placeholder="请输入" v-model="diaForm.expertName"
                                                @change="diaForm.employeeId = diaForm.expertName" style="width: 100%"
                                                clearable  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="性别" prop="genderId">
                                            <el-select v-model="diaForm.genderId" placeholder="请选择" style="width: 100%"
                                                :disabled="flag == 3" @change="changeGender" clearable>
                                                <el-option :label="item.itemText" :value="item.itemValue"
                                                    :key="item.itemValue" v-for="item in sexList" />
                                            </el-select>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="出生日期" prop="birthdate">
                                            <el-date-picker v-model="diaForm.birthdate" type="date" :disabled="flag == 3"
                                                :disabled-date="disabledDate" value-format="YYYY-MM-DD" placeholder="选择日期"
                                                clearable style="width: 100%" @change="changeBirth" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="6">
                                        <el-form-item label="员工编号" prop="employeeCode">
                                            <el-input placeholder="请输入" v-model="diaForm.employeeCode" style="width: 100%"
                                                :disabled="flag == 3" clearable maxlength="20" show-word-limit  />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="年龄" prop="age">
                                            <el-input placeholder="出生日期自动计算" v-model="diaForm.age" disabled>
                                                <template v-slot:append>岁</template>
                                            </el-input>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="民族" prop="nationId">
                                            <el-select clearable v-model="diaForm.nationId" placeholder="请选择"
                                                :disabled="flag == 3" @change="changeNation" style="width: 100%">
                                                <el-option :label="item.itemText" :value="item.itemValue"
                                                    :key="item.itemText" v-for="item in nationList" />
                                            </el-select>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="籍贯" prop="nativePlace">
                                            <el-input placeholder="请输入" v-model="diaForm.nativePlace" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="50" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="6">
                                        <el-form-item label="手机号" prop="phone">
                                            <el-input placeholder="请输入" v-model="diaForm.phone" style="width: 100%"
                                                :disabled="flag == 3" maxlength="20" clearable />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="工作所在地" prop="workLocation">
                                            <el-input placeholder="请输入" v-model="diaForm.workLocation" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="100" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="最高学历" prop="highestDegreeId">
                                            <el-select v-model="diaForm.highestDegreeId" placeholder="请选择"
                                                :disabled="flag == 3" @change="changeEducation" style="width: 100%"
                                                clearable>
                                                <el-option :label="item.itemText" :value="item.itemValue"
                                                    :key="item.itemValue" v-for="item in educationList" />
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="6">
                                        <el-form-item label="所学专业" prop="specialty">
                                            <el-input placeholder="请输入" v-model="diaForm.specialty" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="50" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="毕业院校" prop="graduationSchool">
                                            <el-input placeholder="请输入" v-model="diaForm.graduationSchool"
                                                :disabled="flag == 3" style="width: 100%" clearable  maxlength="50" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="毕业年份" prop="graduationYear">
                                            <el-date-picker v-model="diaForm.graduationYear" type="date"
                                                :disabled="flag == 3" :disabled-date="disabledDate"
                                                value-format="YYYY-MM-DD" placeholder="请选择" clearable style="width: 100%" />
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="参加工作时间" prop="workStartDate">
                                            <el-date-picker v-model="diaForm.workStartDate" type="date"
                                                :disabled="flag == 3" :disabled-date="disabledDate"
                                                value-format="YYYY-MM-DD" placeholder="请选择" clearable style="width: 100%"
                                                @change="changeWorkDate" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row :gutter="20">
                                    <el-col :span="6">
                                        <el-form-item label="工作年限" prop="workExperience">
                                            <el-input placeholder="根据参加时间自动计算" v-model="diaForm.workExperience" disabled>
                                                <template v-slot:append>年</template>
                                            </el-input>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="所属单位" prop="workUnitName">
                                            <popup-tree-input v-if="diaForm.expertType == 1" :data="unitList"
                                                :props="popupTreeProps" :prop="deptForm.parentName == null
                                                    ? $t('message.org.top_menu')
                                                    : diaForm.workUnitName
                                                    " :node-key="'' + deptForm.parentId"
                                                :current-change-handle="changeValue8" />
                                            <el-input placeholder="所属单位" v-else v-model="diaForm.workUnitName"
                                                style="width: 100%" @change="diaForm.workUnitId = diaForm.workUnitName"
                                                :disabled="flag == 3" clearable  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="所属部门" prop="deptName">
                                            <popup-tree-input v-if="diaForm.expertType == 1" :data="unitList1"
                                                :props="popupTreeProps" :prop="deptForm.parentName == null
                                                    ? $t('message.org.top_menu')
                                                    : diaForm.deptName
                                                    " :node-key="'' + deptForm.parentId"
                                                :current-change-handle="changeValue9" />

                                            <el-input placeholder="所属部门" v-model="diaForm.deptName" style="width: 100%"
                                                :disabled="flag == 3" clearable @change="diaForm.deptId = diaForm.deptName"
                                                v-else  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="职务" prop="job">
                                            <el-input placeholder="请输入" v-model="diaForm.job" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row :gutter="20">
                                    <el-col :span="6">
                                        <el-form-item label="职称名称" prop="positionId" v-if="diaForm.expertType == 1">
                                            <el-select v-model="diaForm.positionId" :disabled="flag == 3" placeholder="请选择"
                                                style="width: 100%" @change="changePosition" clearable>
                                                <el-option :label="item.itemText" :value="item.itemValue"
                                                    :key="item.itemValue" v-for="item in positonList" />
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="职称名称" prop="positionName" v-else>
                                            <el-input placeholder="请输入" v-model="diaForm.positionName" :disabled="flag == 3"
                                                style="width: 100%" clearable  maxlength="50" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="微信号" prop="wechat">
                                            <el-input placeholder="请输入" v-model="diaForm.wechat" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="固定电话" prop="telephone">
                                            <el-input placeholder="请输入" v-model="diaForm.telephone" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="电子邮箱" prop="email">
                                            <el-input placeholder="请输入" v-model="diaForm.email" style="width: 100%"
                                                :disabled="flag == 3" clearable maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row :gutter="20">
                                    <el-col :span="12">
                                        <el-form-item label="通讯地址" prop="contactAddress">
                                            <el-input placeholder="请输入" v-model="diaForm.contactAddress" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="50" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="邮政编码" prop="postalCode">
                                            <el-input placeholder="请输入" v-model="diaForm.postalCode" style="width: 100%"
                                                :disabled="flag == 3" clearable maxlength="20" show-word-limit  />
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6">
                                        <el-form-item label="传真" prop="fax">
                                            <el-input placeholder="请输入" v-model="diaForm.fax" style="width: 100%"
                                                :disabled="flag == 3" clearable  maxlength="20" show-word-limit />
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-divider content-position="left">
                                    <span class="title-line">专家指标及信息</span>
                                </el-divider>

                                <el-row :gutter="20">
                                    <el-col :span="24">
                                        <el-form-item label="擅长领域" prop="expertiseAreaIds">
                                            <el-select v-model="diaForm.expertiseAreaIds" placeholder="请选择"
                                                :disabled="flag == 3" @change="changeselect" style="width: 100%" multiple
                                                clearable>
                                                <el-option :label="item.itemText" :value="item.itemValue"
                                                    :key="item.itemText" v-for="item in areaList" />
                                            </el-select>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="24">
                                        <el-form-item label="工作业绩概述:" style="width: 100%" prop="workSummary">
                                            <el-input v-model="diaForm.workSummary" :rows="3"  maxlength="300" show-word-limit
                                                      :disabled="flag == 3" type="textarea" placeholder="300字以内" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tab-pane>

                        <el-tab-pane label="工作经历" name="2">
                            <Work :members="diaForm.workExperienceList" @paramsChange="getWorkInfo"
                            :expertType="diaForm.expertType"  :org-all-list="orgAllList"
                                :countryList="countryList"></Work>
                        </el-tab-pane>
                        <el-tab-pane label="学习经历" name="3">
                            <Learn :members="diaForm.studyExperienceList" @paramsChange="getStudyInfo"
                                :educationList="educationList"></Learn>
                        </el-tab-pane>
                        <el-tab-pane label="学术组织任职" name="4">
                            <Academic :members="diaForm.academicOrganizationList" @paramsChange="getAcademicInfo">
                            </Academic>
                        </el-tab-pane>

                        <el-tab-pane label="职业资格证书" name="5">
                            <Profession :members="diaForm.professionalCertificateList" @paramsChange="getProfessInfo">
                            </Profession>
                        </el-tab-pane>

                        <el-tab-pane label="承担科研的项目" name="6">
                            <Research :members="diaForm.researchProjectList" @paramsChange="getResarchInfo"
                            :isChecked="diaForm.data1Flag" :expertType="diaForm.expertType" :roleList="roleList"  :leveltwoList="leveltwoList" ></Research>
                        </el-tab-pane>

<!--                        <el-tab-pane label="科研学术研究" name="7">-->
                        <el-tab-pane label="科研学术奖励" name="7">
                            <Award :isChecked="diaForm.data2Flag" :members="diaForm.academicAwardList" @paramsChange="getAwardInfo"></Award>
                        </el-tab-pane>

                        <el-tab-pane label="批准专利" name="8">
                            <Approve :isChecked="diaForm.data3Flag" :members="diaForm.patentApprovalList" @paramsChange="getApproveInfo"
                            :expertType="diaForm.expertType" :classList="classList"></Approve>
                        </el-tab-pane>

                        <el-tab-pane label="发表论文" name="9">
                            <Papers :isChecked="diaForm.data4Flag" :members="diaForm.papersList" @paramsChange="getParperInfo" 
                            :expertType="diaForm.expertType" :scoreList="scoreList">
                            </Papers>
                        </el-tab-pane>

                        <el-tab-pane label="学术著作" name="10">
                            <Journal :isChecked="diaForm.data5Flag" :members="diaForm.journalsList" @paramsChange="getJournalInfo" 
                            :expertType="diaForm.expertType" :levelList="levelList">
                            </Journal>
                        </el-tab-pane>

                        <el-tab-pane label="其他" name="11">
                            <Other :members="diaForm.otherAchievementsList" @paramsChange="getOtherInfo"></Other>
                        </el-tab-pane>

                      <el-tab-pane label="变更记录" name="13" v-if="id">
                        <Record :changeLogs="changeLogs"></Record>
                      </el-tab-pane>
                    </el-tabs>
                </div>
            </template>
            <template #footer>
                <div class="dialog-footer" style="float: left" v-if="flag == 3">
                    <el-form  :rules="rulesComment" ref="ruleFormRef" :model="ruleForm">
                        <el-form-item label="审批意见" prop="comment">
                            <el-input :rows="2" type="textarea" placeholder="审批意见" v-model="ruleForm.comment"
                                style="width: 450px" clearable />
                        </el-form-item>
                    </el-form>
                </div>

                <span class="dialog-footer" style="margin-top:20px">
                    <el-button @click="close">关闭</el-button>
                    <el-button type="primary" @click="save" v-if="flag == 1 || flag == 2">保存</el-button>
                    <el-button type="primary" @click="refuse" v-if="flag == 3">驳回</el-button>
                    <el-button type="primary" @click="pass" v-if="flag == 3">通过</el-button>
                </span>

            </template>
        </el-dialog>
    </div>
</template>

<script>
import flowChart from "@/components/PublicProcess/Chart/flowChart.vue";
import {
    addForm,
    allowProcess,
    editForm,
    getDetailById,
    getDictionary,
    getUser,
    getbgjltailByiId,
    refuseProcess
} from "@/views/expert/api/expertsManager";
import { ElAlert } from "element-plus";

import * as proxy from "@/constants/proxy";
import request from "@/utils/request";
import Record from '@/views/expert/components/record/record.vue';
import UserListModal from "@/views/project/components/UserListModal/index.vue";
import { checkEmailNumber, checkPhoneNumber } from "@/views/science/common/common";
import PopupTreeInput from "@/views/science/components/PopupTreeInput/index.vue";
import PlatformFiles from "@/views/science/components/platformFiles/platformFiles.vue";
import { Modals, tips } from "@/views/science/components/tips/tips";
import { nextTick, onMounted, reactive, ref, toRefs, watch } from "vue";
import Academic from "./academic.vue";
import Approve from "./approve.vue";
import Award from "./award.vue";
import Journal from "./journal.vue";
import Learn from "./learn.vue";
import Other from "./other.vue";
import Papers from "./papers.vue";
import Profession from "./profession.vue";
import Research from "./research.vue";
import Work from "./work.vue";

export default {
    components: {
        PlatformFiles,
        UserListModal,
        PopupTreeInput,
        Record,
        Work,
        Learn,
        Academic,
        Profession,
        Research,
        Award,
        Approve,
        Papers,
        Other,
        Journal,
        flowChart,
        ElAlert,
    },
    props: {
        dialogVisable: {
            type: Boolean,
            default: false,
        },

        // falg  1:新增  2:编辑  3:详情
        flag: {
            type: String,
            default: 1,
        },
        id: {
            type: String,
            default: "",
        },
      orgAllList: {
          type: Array,
          default: () => []
      }
    },
    setup(props, { emit }) {
      const detail_loading = ref(false);
        watch(
            () => props.dialogVisable,

            (value) => {
                nextTick(() => {
                    // 深度监听.只有在id存在的时候调用详情的接口
                    if (props.flag == 1) {
                        data.diaForm.workExperienceList = [];
                        data.diaForm.studyExperienceList = [];
                        data.diaForm.academicOrganizationList = [];
                        data.diaForm.professionalCertificateList = [];
                        data.diaForm.researchProjectList = [];
                        data.diaForm.academicAwardList = [];
                        data.diaForm.patentApprovalList = [];
                        data.diaForm.papersList = [];
                        data.diaForm.journalsList = [];
                        data.diaForm.otherAchievementsList = [];
                        data.changeLogs= [];
                        initDiaForm()
                        DiaForm.value.resetFields();
                    } else if (props.flag == 2) {
                        getDetail(props.id);
                        getbgjltail(props.id)
                    } else if (props.flag == 3) {
                        getDetail(props.id);

                        data.tabId = "12";
                    }
                });
            },

            { deep: true, immediate: true }
        );

        // 发送请求
        onMounted(() => {
            // 获取数据字典
            getUserList();

            getUnitList();
            getUnitList1();

            getCodeList();
            initDiaForm()

        });

        const ruleFormRef = ref();

        const ruleForm = reactive({
            comment: "",
        });

        const rulesComment = reactive({
            comment: [{ required: true, message: "请输入审核意见", trigger: "change" }],
        });

        let DiaForm = ref();
        let data = reactive({
            dealInVisible: false,
            times: null,
            tabId: "1",
            processInstanceId: "",
            taskId: "",
            expertTypeList: [
                { itemValue: "1", itemText: "公司内部人才" },
                { itemValue: "2", itemText: "公司外部人才" },
            ],
            expertNameList: [],
            unitList: [],
            unitList1: [],
            levelList: [],

            sexList: [],
            classList: [],

            nationList: [],
            areaList: [],

            educationList: [],
            roleList: [],
            scoreList: [],
          leveltwoList: [],
            countryList: [],
            positonList: [],
            userList: [],
            projectList: [], //项目
            technologyList: [], //技术分类
            awardList: [], //软著状态
            popupTreeProps: {
                label: "name",
                children: "children",
            },
            diaForm: {},

            files: [],
            changeLogs: [],
        });
        const initDiaForm = ()=>{
          data.diaForm= {
                type: 2,
                id: "",
                nationId: "",
                nation: "",
                expertType: "", //专家内型
                expertName: "", //人才姓名
                employeeId: "",
                genderId: "",
                gender: "", //性别
                birthdate: "", //出生日期
                employeeCode: "", //员工编号
                workLocation: "", //工作所在地
                nativePlace: "",
                workExperience: "",
                job: "",
                positionId: "",
                positionName: "",
                workUnitId: "",
                workUnitName: "",
                deptId: "",
                deptName: "",
                phone: "",
                highestDegreeId: "",
                highestDegree: "",
                specialty: "",
                graduationSchool: "",
                graduationYear: "",
                workStartDate: "",
                workSummary: "",
                data1Flag: 1,
                data2Flag: 1,
                data3Flag: 1,
                data4Flag: 1,
                data5Flag: 1,
                expertiseAreaIds: [],
                expertiseAreas: [],
                academicOrganizationList: [],
                otherAchievementsList: [],
                patentApprovalList: [],
                professionalCertificateList: [],
                researchProjectList: [],
                studyExperienceList: [],
                workExperienceList: [],
                academicAwardList: [],
                papersList: [],
                journalsList: [],
            }}
        const deptForm = {
            parentId: 0,
            parentName: "",
        };
        const checkData = reactive( {
            data1Flag: 1,
            data2Flag: 1,
            data3Flag: 1,
            data4Flag: 1,
            data5Flag: 1,
        })
        // 规则校验
        let rules = reactive({
            expertType: [{ required: true, message: "请选择专家类型", trigger: "blur" }],
            workUnitName: [{ required: true, message: "请选择所属单位", trigger: "blur" }],
            deptName: [{ required: true, message: "请选择所属部门", trigger: "blur" }],
            expertName: [{ required: true, message: "请选择人才姓名", trigger: "change" }],
            nationId: [{ required: true, message: "请选择民族", trigger: "change" }],
            genderId: [{ required: true, message: "请选择性别", trigger: "change" }],
            birthdate: [{ required: true, message: "请选择出生日期", trigger: "change" }],
            employeeCode: [{ required: true, message: "请输入员工编号", trigger: "change" }],
            workLocation: [{ required: true, message: "请输入工作所在地", trigger: "change" }],
            job: [{ required: true, message: "请输入职务", trigger: "change" }],
            nativePlace: [{ required: true, message: "请输入籍贯", trigger: "change" }],
            phone: [
                { required: true, message: "请输入手机号", trigger: "change" },
                { validator: checkPhoneNumber, trigger: "blur" },
            ],
            highestDegreeId: [{ required: true, message: "请选择最高学历", trigger: "change" }],
            positionId: [{ required: true, message: "请选择职称", trigger: "change" }],
            positionName: [{ required: true, message: "请选择职称", trigger: "change" }],
            specialty: [{ required: true, message: "请输入所学专业", trigger: "change" }],
            graduationSchool: [
                { required: true, message: "请输入毕业院校", trigger: "change" },
            ],
            graduationYear: [{ required: true, message: "请选择毕业年份", trigger: "change" }],
            workStartDate: [
                { required: true, message: "请选择参加工作时间", trigger: "change" },
            ],
            expertiseAreaIds: [
                { required: true, message: "请选择擅长领域", trigger: "change" },
            ],
            email: [
                { required: true, message: "请输入电子邮箱", trigger: "change" },
                { validator: checkEmailNumber, trigger: "blur" },
            ],
        });
        const changeExpertType = ()=>{
            data.diaForm.expertName = ''
            data.diaForm.employeeId = ''
            console.log(data.diaForm.expertType,'diaForm.expertType');
        }
        let refuse = () => {
            ruleFormRef.value.validate((valid) => {
                if (valid) {
                    Modals("是否驳回本次内容", "提示", "warning")
                        .then(async () => {

                            refuseProcess({
                                procInsId: data.processInstanceId,
                                comment: ruleForm.comment,
                                businessKey: props.id,
                                businessType: "YW05",
                                random: new Date().valueOf(),
                            })
                                .then((res) => {
                                    if (res.data.code == 200) {
                                        ruleFormRef.value.resetFields();

                                        emit("changerRefuse");
                                    } else {
                                        tips(res.data.message, "warning");
                                    }
                                })
                                .catch(() => {
                                    console.log("点击了取消");
                                });

                        })

                }
            });
        };

        //通过
        let pass = () => {
            ruleFormRef.value.validate((valid) => {
                if (valid) {
                    Modals("是否通过本次内容", "提示", "warning")
                        .then(async () => {
                            allowProcess({
                                procInsId: data.processInstanceId,
                                comment: ruleForm.comment,
                                businessKey: props.id,
                                businessType: "YW05",
                                random: new Date().valueOf(),
                            }).then((res) => {
                                if (res.data.code == 200) {
                                    ruleFormRef.value.resetFields();

                                    emit("changeSuccess");

                                } else {
                                    tips(res.data.message, "warning");
                                }
                            });
                        })
                        .catch(() => {
                            console.log("点击了取消");
                        });
                }
            });
        };

        let dealInCheck = (id) => {
            data.times = setInterval(() => {
                getDetailById(id).then((res) => {
                    let resData = res.data.data;

                    if (resData.status == 2 || resData.status == 1) {
                        data.dealInVisible = false;

                        emit("changeDialog", "1");

                        clearTimeout(data.times);
                    }
                });
            }, 1000);
        };

        // 保存
        let save = () => {
            DiaForm.value.validate((valid) => {
                if(checkData.data1Flag) {
                console.log(data.diaForm.researchProjectList,'data.diaForm.researchProjectList');
                if(data.diaForm.researchProjectList.length < 1){
                tips("承担科研的项目中需要至少一条数据", "warning");
                return false;
                }else{
                //   let panduan = 0 ;
                //   data.diaForm.researchProjectList.forEach(item => {
                //     for (let i = 0; i < data.diaForm.researchProjectList.length; i++) {
                //       if(item.workContent == '' || item.workContent == null ){
                //         panduan = 1;
                //       }
                //       if(item.projectType == '' || item.projectType == null  ){
                //         panduan = 2;

                //       }
                //       if(item.industryClassify == '' || item.industryClassify == null  ){
                //         panduan = 3;
                //       }
                //       if(item.businessNature == '' || item.businessNature == null  ){
                //         panduan = 4;
                //       }
                //       if(item.projectScale == '' || item.projectScale == null  ){
                //         panduan = 5;
                //       }
                //     }
                //   });
                //   if(panduan == 1){
                //     tips("承担科研的项目中主要工作内容不能为空", "warning");
                //     return false;
                //   }else if(panduan == 2){
                //     tips("承担科研的项目中项目类型不能为空", "warning");
                //     return false;
                //   }else if(panduan == 3){
                //     tips("承担科研的项目中行业分类不能为空", "warning");
                //     return false;
                //   }else if(panduan == 4){
                //     tips("承担科研的项目中经营性质不能为空", "warning");
                //     return false;
                //   }else if(panduan == 5){
                //     tips("承担科研的项目中项目规模不能为空", "warning");
                //     return false;
                //   }
                }
              }
              if(checkData.data2Flag) {
                if( data.diaForm.academicAwardList.length < 1){
                  tips("科研学术奖励中需要至少一条数据", "warning");
                  // event.stopPropagation();
                  return false;
                }else {
                //   let panduan = 0 ;
                //   data.diaForm.academicAwardList.forEach(item => {
                //     for (let i = 0; i < data.diaForm.academicAwardList.length; i++) {
                //       if(item.awardMethodId == null || item.awardMethodId == ''){
                //         panduan = 1;
                //       }
                //     }
                //   });
                //   if(panduan == 1){
                //     tips("科研学术奖励数据中获奖方式不能为空", "warning");
                //     // event.stopPropagation();
                //     return false;
                //   }

                }
              }
              if(checkData.data3Flag) {
                if(data.diaForm.patentApprovalList.length < 1){
                  tips("批准专利中需要至少一条数据", "warning");
                  return false;
                }else {
                //   let panduan = 0 ;
                //   data.diaForm.patentApprovalList.forEach(item => {
                //     for (let i = 0; i < data.diaForm.patentApprovalList.length; i++) {
                //       if(item.intellectualPropertyType == '' || item.intellectualPropertyType == null   ){
                //         panduan = 1;
                //       }
                //     }
                //   });
                //   if(panduan == 1){
                //     tips("代表性专利中知识产权类别不能为空", "warning");
                //     return false;
                //   }

                }
              }
              if(checkData.data4Flag) {
                if(data.diaForm.papersList.length < 1){
                  tips("发表论文中需要至少一条数据", "warning");
                  return false;
                }else {
                //   let panduan = 0 ;
                //   data.diaForm.papersList.forEach(item => {
                //     for (let i = 0; i < data.diaForm.papersList.length; i++) {
                //       if(item.isMasterWork == '' || item.isMasterWork == null  ){
                //         panduan = 1;
                //       }
                //     }
                //   });
                //   if(panduan == 1){
                //     tips("发表论文中知识产权类别不能为空", "warning");
                //     return false;
                //   }

                }
              }
              if(checkData.data5Flag) {
                if(data.diaForm.journalsList.length < 1){
                  tips("学术著作中需要至少一条数据", "warning");
                  return false;
                }else {
                //   let panduan = 0 ;
                //   data.diaForm.journalsList.forEach(item => {
                //     for (let i = 0; i < data.diaForm.journalsList.length; i++) {
                //       if(item.isMasterWork == '' || item.isMasterWork == null  ){
                //         panduan = 1;
                //       }
                //     }
                //   });
                //   if(panduan == 1){
                //     tips("学术著作中是否代表作不能为空", "warning");
                //     return false;
                //   }

                }
              }
              console.log(props.flag,'props.flag');
                // 校验通过
                if (valid) {
                    //flag 1 新增  2 编辑  3  详情
                    if (props.flag == 1) {
                        data.diaForm.id = "";
                        for(let key in checkData){
                            data.diaForm[key] = checkData[key]
                        }
                        detail_loading.value = true;
                        addForm({...data.diaForm}).then(() => {
                            tips("新增成功", "success");

                            DiaForm.value.resetFields();
                          data.diaForm.positionName=''
                          data.diaForm.positionId=''
                            emit("changeDialog", "1");
                        }).finally(() => detail_loading.value = false);
                    } else {
                      detail_loading.value = true;
                      for(let key in checkData){
                            data.diaForm[key] = checkData[key]
                        }
                        editForm({...data.diaForm}).then(() => {
                            tips("编辑成功", "success");

                            // DiaForm.value.resetFields();
                          data.diaForm.positionName=''
                          data.diaForm.positionId=''
                            emit("changeDialog", "1");
                        }).finally(() => detail_loading.value = false);
                    }
                } else {
                    return tips("请将基本信息补充完整", "warning");
                }
            });
        };
        // 通过详情查询id

        let getDetail = async (id) => {
          detail_loading.value = true;
            let res = await getDetailById(id);
          detail_loading.value = false;
          console.log(data.diaForm,res.data.data,'getgetDetailByIdDetail');

            data.diaForm = res.data.data;
            console.log(checkData,'checkData');
            for(let key in checkData){
               checkData[key] = data.diaForm[key]
            }
            data.processInstanceId = res.data.data.processInstanceId;

            data.taskId = res.data.data.taskId;
        };
      let getbgjltail = async (alterid) => {
        let res = await getbgjltailByiId(alterid);
        console.log(11111111111111111111111111,res.data.data)
        data.changeLogs = res.data.data
      };


      // 技术分类/软著状态===>数据字典

        let getCodeList = () => {
            getDictionary([
                "SEX",
                "NATIONALITY","XMZX_LEVEL_TYPE",
                "EDUCATION",
                "ZJYRC_ZCMC",
                "ZJYRC_SCLY",
                "ZJYRC_SZGL",
                "KJSL_PATENT_TYPE",
                "KJSL_ACADEMIC_WORK_LEVEL",
                "KJSL_BUSINESS_SECTOR",
              "KJSL_MEMBER_ROLE",
            ]).then((res) => {
                data.sexList = res.data.data.SEX;
              data.leveltwoList = res.data.data.XMZX_LEVEL_TYPE;

              data.nationList = res.data.data.NATIONALITY;

                data.educationList = res.data.data.EDUCATION;

                data.positonList = res.data.data.ZJYRC_ZCMC;

                data.areaList = res.data.data.ZJYRC_SCLY;

                data.countryList = res.data.data.ZJYRC_SZGL;

                data.classList = res.data.data.KJSL_PATENT_TYPE;

                data.scoreList = res.data.data.KJSL_BUSINESS_SECTOR;

                data.levelList = res.data.data.KJSL_ACADEMIC_WORK_LEVEL;
                data.roleList = res.data.data.KJSL_MEMBER_ROLE;
            });
        };

        let getWorkInfo = (parms) => {
            data.diaForm.workExperienceList = parms;
        };

        let getStudyInfo = (parms) => {
            data.diaForm.studyExperienceList = parms;
        };

        let getAcademicInfo = (parms) => {
            data.diaForm.academicOrganizationList = parms;
        };

        let getProfessInfo = (parms) => {
            data.diaForm.professionalCertificateList = parms;
        };

        let getOtherInfo = (parms) => {
            data.diaForm.otherAchievementsList = parms;
        };

        let getResarchInfo = (parms) => {
            data.diaForm.researchProjectList = parms.list ? parms.list : []
            checkData.data1Flag = Number(!parms.checked)
        }
        let getAwardInfo = (parms) => {
            data.diaForm.academicAwardList = parms.list ? parms.list : []
            checkData.data2Flag = Number(!parms.checked)
        }
        let getApproveInfo = (parms) => {
            data.diaForm.patentApprovalList = parms.list ? parms.list : []
            checkData.data3Flag = Number(!parms.checked)
        }
        let getParperInfo = (parms) => {
            data.diaForm.papersList  =  parms.list ? parms.list : []
            checkData.data4Flag = Number(!parms.checked)
        }
        let getJournalInfo = (parms) => {
            data.diaForm.journalsList =  parms.list ? parms.list : []
            checkData.data5Flag = Number(!parms.checked)
        }
        // 项目

        let getUserList = () => {
            getUser({}).then((res) => {
                data.userList = res.data.data;
            });
        };

        let changeEducation = (id) => {
            let itemText = data.educationList.find((item) => item.itemValue == id).itemText;
            data.diaForm.highestDegree = itemText;
        };
        // 职务Name
        let changePosition = (id) => {
            let itemText = data.positonList.find((item) => item.itemValue == id).itemText;
            data.diaForm.positionName = itemText;
        };

        let changeGender = (id) => {
            let itemText = data.sexList.find((item) => item.itemValue == id).itemText;
            data.diaForm.gender = itemText;
        };

        let changeNation = (id) => {
            let itemText = data.nationList.find((item) => item.itemValue == id).itemText;
            data.diaForm.nation = itemText;
        };

        let handleProjectLeader = (user) => {
            data.diaForm.expertName = user.cname;
            data.diaForm.employeeId = user.userId;
            getPeople(user.userCode);
        };

        const getPeople = (id) => {
            return request({
                url: proxy.CHECC_API_CMS + "/user/getList",
                method: "post",
                data: { empcode: id },
            }).then((res) => {
                console.log("res", res.data.data.records[0]);
                let resdata = res.data.data.records[0];
                data.diaForm.genderId = resdata.gender;
                data.diaForm.gender = resdata.gendertext;
                data.diaForm.birthdate = resdata.birth.substring(0, 10);
                //根据出生日期算年龄
                if (data.diaForm.birthdate) {
                    let birthDayTime = new Date(data.diaForm.birthdate).getTime();
                    let nowTime = new Date().getTime();
                    data.diaForm.age = Math.ceil((nowTime - birthDayTime) / 31536000000);
                }
                data.diaForm.nationId = resdata.nationDict;
              data.diaForm.employeeCode = resdata.empcode
              data.diaForm.nation = resdata.nation;
                data.diaForm.phone = resdata.phone;
                data.diaForm.highestDegreeId = resdata.educationDict;
                data.diaForm.highestDegree = resdata.educationBackground;
                data.diaForm.specialty = resdata.typeOfWork;
                data.diaForm.workStartDate = resdata.hiredate.substring(0, 10);
                //参加工作时间
                if (data.diaForm.workStartDate) {
                    let DayTime = new Date(data.diaForm.workStartDate).getTime();
                    let nowTime = new Date().getTime();
                    data.diaForm.workExperience = Math.ceil((nowTime - DayTime) / 31536000000);
                }
                data.diaForm.workUnitName = resdata.orgname;
                data.diaForm.workUnitId = resdata.orgid;
                data.diaForm.deptName = resdata.deptName;
                data.diaForm.deptId = resdata.deptId;
                data.diaForm.job = resdata.selectOrgs;
                // data.diaForm.positionId = resdata.technicalDict;
                data.diaForm.positionName = resdata.technicalTitle;
                data.diaForm.email = resdata.email;
            });
        };
        let changeselect = (val) => {
            let arr = [];
            data.areaList.forEach((item) => {
                for (let i = 0; i < val.length; i++) {
                    if (item.itemValue == val[i]) {
                        arr.push(item.itemText);
                    }
                }
            });
            data.diaForm.expertiseAreas = arr;
        };

        //   出生计算年龄
        let changeBirth = (value) => {
            let birthDayTime = new Date(value).getTime();
            let nowTime = new Date().getTime();
            data.diaForm.age = Math.ceil((nowTime - birthDayTime) / 31536000000);
        };

        let changeWorkDate = (value) => {
            let DayTime = new Date(value).getTime();
            let nowTime = new Date().getTime();
            data.diaForm.workExperience = Math.ceil((nowTime - DayTime) / 31536000000);
        };

        let disabledDate = (date) => {
            return date.getTime() > Date.now();
        };

        // 单位公司
        let getUnitList = () => {
            return request({
                url: proxy.CHECC_API_CMS + "/org/getSysOrgList",
                method: "get",
            }).then((res) => {
                data.unitList = res.data.data;
            });
        };
        // 部门
        let getUnitList1 = () => {
            return request({
                url: proxy.CHECC_API_CMS + "/org/tree",
                method: "get",
            }).then((res) => {
                data.unitList1 = res.data.data;
            });
        };

        // 关闭清除对话框里面的数据,附件.变更记录也要删除
        let close = () => {

            if (props.flag == 3) {
                ruleFormRef.value.resetFields();
            }
            data.tabId = "1";
        //     DiaForm.value.resetFields();
          data.diaForm.positionName=''
          data.diaForm.positionId=''
            emit("changeDialog");
        };
        const changeValue8 = (item) => {
            data.diaForm.workUnitId = item.id;
            data.diaForm.workUnitName = item.name;
        };
        const changeValue9 = (item) => {
            data.diaForm.deptId = item.id;
            data.diaForm.deptName = item.name;
        };

        return {
            disabledDate,

            DiaForm,
            deptForm,
            changeValue8,
            changeValue9,
            getUnitList,
            getUnitList1,
            getWorkInfo,
            getStudyInfo,
            getAcademicInfo,
            getProfessInfo,
            getOtherInfo,
            getResarchInfo,
            getAwardInfo,
            getParperInfo,
            getJournalInfo,
            getApproveInfo,
            rules,
            getUserList,
            getCodeList,
            changeEducation,
            changePosition,
            changeselect,
            changeBirth,
            changeWorkDate,
            changeGender,
            changeNation,
            ...toRefs(data),
            close,
            save,
            ruleForm,
            rulesComment,
            pass,
            dealInCheck,
            ruleFormRef,
            refuse,
            changeExpertType,
            handleProjectLeader,
          detail_loading
        };
    },
};
</script>

<style scoped lang="scss">
.title-line {
    color: #409eff;
}

.dialog-footer {
    display: flex;
    justify-content: end;
}

:deep(.el-dialog__body) {
    display: none;
}

// 滚动条
:deep(.demo-tabs > .el-tabs__content) {
    max-height: 500px;
    overflow-y: scroll;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
</style>
